from django.contrib import admin
from .models import SurveyRecord, SurveyImage, FavoriteLocation

class SurveyImageInline(admin.TabularInline):
    model = SurveyImage
    extra = 1

@admin.register(SurveyRecord)
class SurveyRecordAdmin(admin.ModelAdmin):
    list_display = ['location_name', 'user', 'survey_date', 'created_at']
    list_filter = ['survey_date', 'created_at', 'user']
    search_fields = ['location_name', 'address', 'user__username']
    readonly_fields = ['created_at', 'updated_at']
    inlines = [SurveyImageInline]
    
    fieldsets = (
        ('基本信息', {
            'fields': ('user', 'location_name', 'address', 'survey_date')
        }),
        ('地理位置', {
            'fields': ('latitude', 'longitude', 'orientation')
        }),
        ('其他信息', {
            'fields': ('notes', 'created_at', 'updated_at')
        }),
    )

@admin.register(SurveyImage)
class SurveyImageAdmin(admin.ModelAdmin):
    list_display = ['survey_record', 'orientation', 'uploaded_at']
    list_filter = ['uploaded_at', 'survey_record__user']
    search_fields = ['survey_record__location_name', 'orientation']
    readonly_fields = ['uploaded_at']

@admin.register(FavoriteLocation)
class FavoriteLocationAdmin(admin.ModelAdmin):
    list_display = ['name', 'user', 'created_at']
    list_filter = ['created_at', 'user']
    search_fields = ['name', 'address', 'user__username']
    readonly_fields = ['created_at']
